//
//  WPPEFTableViewCell.m
//  wobingwoyi
//
//  Created by WGP on 2017/3/1.
//  Copyright © 2017年 WGP. All rights reserved.
//

#import "WPPEFTableViewCell.h"

@interface WPPEFTableViewCell ()

@property(nonatomic,strong)UIView *topView;
@property(nonatomic,strong)UILabel *tjTitleLabel;
@property(nonatomic,strong)UIButton *sendDocBtn;
@property(nonatomic,strong)UILabel *descpLabel;
@property(nonatomic,strong)UIView *PEFContentView;
@property(nonatomic,strong)UIView *bottomView;
@property(nonatomic,strong)UILabel *tjTimeLabel;

@property(nonatomic,strong)UIImageView *imageView1;
@property(nonatomic,strong)UIImageView *imageView2;
@property(nonatomic,strong)UIImageView *imageView3;

@end
@implementation WPPEFTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super  initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        self.contentView.backgroundColor = GlobalBgColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupUI];
    }
    return self;
}

-(void)setupUI
{
    self.topView = [UIView new];
    self.topView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.topView];
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(10);
        make.left.right.equalTo(self.contentView);
        make.height.mas_equalTo(44);
    }];
    
    UIImageView *line1 = [UIImageView lineImageView];
    UIImageView *line2 = [UIImageView lineImageView];
    [self.topView addSubview:line1];
    [self.topView addSubview:line2];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self.topView);
        make.height.mas_equalTo(0.5);
    }];
    [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.equalTo(self.topView);
        make.height.mas_equalTo(0.5);
    }];
    
    UIImageView *tjTitleImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tjTitle"]];
    [self.topView addSubview:tjTitleImageView];
    [tjTitleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.topView);
        make.left.equalTo(self.topView).offset(10);
    }];
    
    self.tjTitleLabel = [UILabel new];
    self.tjTitleLabel.font = [UIFont systemFontOfSize:15];
    self.tjTitleLabel.textColor = [UIColor colorWithHexString:@"#999999"];
    self.tjTitleLabel.text = @"请填写体检标题";
    [self.topView addSubview:self.tjTitleLabel];
    [self.tjTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(tjTitleImageView.mas_right).offset(10);
        make.centerY.equalTo(self.topView);
    }];
    
    self.sendDocBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.sendDocBtn setBackgroundImage:[UIImage imageNamed:@"tjSendDoc_normal"] forState:UIControlStateNormal];
    [self.sendDocBtn setBackgroundImage:[UIImage imageNamed:@"tjSendDoc_highlight"] forState:UIControlStateHighlighted];
    [self.sendDocBtn addTarget:self action:@selector(sendDocBtn) forControlEvents:UIControlEventTouchUpInside];
    [self.topView addSubview:self.sendDocBtn];
    [self.sendDocBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.topView);
        make.right.equalTo(self.topView).offset(-10);
    }];
    
    
    CGFloat width = (SCREEN_WIDTH-4*10)/3.0;
    CGFloat height = 9/11.0*width;
    
    self.PEFContentView = [UIView new];
    self.PEFContentView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.PEFContentView];
    [self.PEFContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topView.mas_bottom);
        make.left.right.equalTo(self.contentView);
    }];
    
    self.descpLabel = [UILabel new];
    self.descpLabel.font = [UIFont systemFontOfSize:14];
    self.descpLabel.numberOfLines = 0;
    self.descpLabel.backgroundColor = [UIColor whiteColor];
    self.descpLabel.textColor = [UIColor colorWithHexString:@"#333333"];
    [self.PEFContentView addSubview:self.descpLabel];
    [self.descpLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.PEFContentView).offset(10);
        make.right.equalTo(self.contentView).offset(-10);
        make.top.equalTo(self.PEFContentView).offset(15);
    }];
    
    self.imageView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"noImages"]];
    self.imageView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"noImages"]];
    self.imageView3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"noImages"]];
    
    [self.PEFContentView addSubview:self.imageView1];
    [self.PEFContentView addSubview:self.imageView2];
    [self.PEFContentView addSubview:self.imageView3];
    
    [self.imageView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.PEFContentView).offset(10);
        make.top.equalTo(self.descpLabel.mas_bottom).offset(15);
        make.height.mas_equalTo(height);
        make.width.mas_equalTo(width);
        make.bottom.equalTo(self.PEFContentView).offset(-10);
    }];
    
    [self.imageView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imageView1.mas_right).offset(10);
        make.width.height.centerY.equalTo(self.imageView1);
    }];
    
    [self.imageView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imageView2.mas_right).offset(10);
        make.width.height.centerY.equalTo(self.imageView1);
    }];
    
    self.bottomView = [UIView new];
    self.bottomView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.bottomView];
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.equalTo(self.contentView);
        make.height.mas_equalTo(44);
        make.top.equalTo(self.PEFContentView.mas_bottom);
    }];
    
    UIImageView *line3 = [UIImageView lineImageView];
    UIImageView *line4 = [UIImageView lineImageView];
    [self.bottomView addSubview:line3];
    [self.bottomView addSubview:line4];
    [line3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self.bottomView);
        make.height.mas_equalTo(0.5);
    }];
    [line4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.equalTo(self.bottomView);
        make.height.mas_equalTo(0.5);
    }];
    
    UIImageView *tjTimeImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"caseTimeImage"]];
    [self.bottomView addSubview:tjTimeImageView];
    [tjTimeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.bottomView);
        make.left.equalTo(self.bottomView).offset(10);
    }];
    
    self.tjTimeLabel = [UILabel new];
    self.tjTimeLabel.font = [UIFont systemFontOfSize:14];
    self.tjTimeLabel.textColor = [UIColor colorWithHexString:@"#333333"];
    [self.bottomView addSubview:self.tjTimeLabel];
    [self.tjTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(tjTimeImageView.mas_right).offset(10);
        make.centerY.equalTo(self.bottomView);
    }];
}

-(void)sendDocBtnDidClick
{
    
}

-(void)setModel:(WPPEFModel *)model
{
    _model = model;
    self.descpLabel.text = model.descStr;
    
    if (model.title.length)
    {
        self.tjTitleLabel.text = model.title;
        self.tjTitleLabel.textColor = [UIColor colorWithHexString:@"#333333"];
    }
    else
    {
        self.tjTitleLabel.text = @"请填写体检标题";
        self.tjTitleLabel.textColor = [UIColor colorWithHexString:@"#999999"];
    }
    
    self.tjTimeLabel.text = model.timeStr;
    
//    self.imageView1.image = [UIImage imageNamed:@"banner"];
//    self.imageView2.image = [UIImage imageNamed:@"banner"];
//    self.imageView3.image = [UIImage imageNamed:@"banner"];
}

@end
